﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MedicalAdviser.Portable.DataTypes.DomainObjects;
using dts = MedicalAdviser.Portable.DataTypes;

namespace MedicalAdviser.DAL
{
    public class SelectOperation
    {
        public static List<dts.DomainObjects.CdoDrug> EquivalentsDrugs( dts.DomainObjects.CdoDrug search  )
        {
            List<dts.DomainObjects.CdoDrug> list = new List<CdoDrug>();
            foreach (var result in DrugContext.Context().spSelect_MedicamentosEquivalentes(search.CodGrupoHomogeneo, search.CodEmbalagem, search.CodMedicamento, search.Pvp) )   
            {
                list.Add(WrappeTypes.ConvertSearchTypes.GetEquivalentsLowCost(result));
            }
            return list;
        }

        public static List<dts.DomainObjects.CdoDrug> QuickSearch(dts.DomainObjects.SearchDrug search)
        {
            List<dts.DomainObjects.CdoDrug> list = new List<CdoDrug>();

            foreach (spSelect_MedsSearchQuick_Result result in   DrugContext.Context().spSelect_MedsSearchQuick(search.AccessToken, search.GenericSearch))
            {
                 list.Add( WrappeTypes.ConvertSearchTypes.ConvertQuickSearchTypes(result) );
            }
            return list;
        }

        public static dts.DomainObjects.CdoDrug GetDrugInfo(int embId, int medId, String token)
        {
            var tOut = DrugContext.Context().spSelect_MedicamentoInfo(embId, medId,token).FirstOrDefault();
            if (tOut == null) return null;

            return WrappeTypes.ConvertSearchTypes.ConvertDrugInformation(tOut);
           
        }


    }
}
